<%@ include file="/en/jsp/static.jsp" %>
<%@ page import="java.util.*,linuxbox.reservation.logic.*,linuxbox.resource.logic.*" %>
<%@ taglib uri="/linuxbox/common.tld" prefix="Common" %>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>

<jsp:useBean id="home" class="linuxbox.resource.logic.BoxResourceCat"/>
<%
 BoxResource resource = BoxResource.getInstance();
%>
<script Language="JavaScript">
  function confirmDel(entry)
  {
    return confirm("Are you sure to delete " + entry);
  }
</script>

<FORM action="<%=BoxStatic.servletDir%>BoxResourceCatAction" method="POST">

<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
  <tr>
    <td>
      &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
      <b><%=boxName%> - Resource Category</b>
    </td>
    <td align=right>
      <a href="<%=BoxStatic.jspDir%>resource/BoxResource.jsp">
        Resource List
      </a>
    </td>
  </tr>
</table>

<hr width="100%" color=#E06000 align=left>

<table width="100%" border=0 cellpadding=0 cellspacing=0>
  <tr>
    <td>
      <% if (sec.isResourceAdmin())
        {%>
      <input type="submit" name="SubmitEdit" value="Add...">
      <%}%>
    </td>
  </tr>
  <tr>
    <%
      java.util.Iterator it = home.getAllCategories();
      if ( it != null && it.hasNext())
      {
        int count=0;
    %>
    <td>
      <TABLE WIDTH="100%" BORDER=0 CELLSPACING=1 CELLPADDING=1 bgColor=#dddddd>
        <TR bgColor=#7EC1F3>
          <TH width="1%">Name</TH>
          <TH width="90%">Description</TH>
          <TH width="1%" nowrap>Resource Count</TH>
          <TH width="1%" nowrap>Delete</TH>
        </TR>
        <Common:Iteration name="entry" type="linuxbox.resource.logic.BoxResourceCatEntry" group="<%=it%>">
          <TR <% if ((count++ % 2) == 0) out.print("bgcolor=#f0f0f0"); %>>
            <TD width="20%"><a href="<%=BoxStatic.servletDir%>BoxResourceCatAction?ID=<%=entry.getID()%>&SubmitEdit=edit"><%=entry.getName()%></a></TD>
            <TD width="1%"><%=entry.getDescription()%></TD>
            <TD width="15%"  align=center><%=resource.getResourceCountByCat(entry.getID())%><a href="<%=BoxStatic.servletDir%>BoxResourceAction?SORTBY=category" ALT="View resources">&nbsp;(View)</a></TD>
            <TD align = center>
            <%  //Can only delete it when there is no resource belongs to it
              if (sec.isResourceAdmin() && resource.getResourceCountByCat(entry.getID()) ==0 )
                { %>
              <a href="<%=BoxStatic.servletDir%>BoxResourceCatAction?SubmitDelete=del&ID=<%=entry.getID()%>" Onclick='return confirmDel("<%=entry.getName()%>")'>Delete</a>
            <%  }%>
            </TD>
          </TR>
        </Common:Iteration>
      </TABLE>
    </td>
    <%
      }
      else
      {
        out.print("<td align=center>There is no resource category!</td>");
      }
    %>
  </tr>
</table>

<hr width="100%" color=#E06000 align=left>

</form>

<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
